import axios from 'axios'
// import {router} from 'react'
// import {Logout} from '@/store/modules/user.js'
// import {useDispatch} from 'react-redux'
// import {useNavigate} from 'react-router-dom';

const https=axios.create({
    baseURL:'https://geek.itheima.net/v1_0',
    timeout:5000
})


//请求拦截
https.interceptors.request.use( 
    (config)=>{
        // const token=localStorage.getItem('token')
        // const navigate=useNavigate()
        // if(token){
        //  config.headers.Authorization=`Bearer ${token}`//添加请求头
            
        // }else{
             
        // }
        return config
    },
    (error)=>{
        return Promise.reject(error)
    }
)


//响应拦截
https.interceptors.response.use(
    (res)=>{

        return res.data
    },
    (err)=>{
        // if(err.response.status === 401){
        //     console.log('进入401处理逻辑') 
        //     localStorage.removeItem('refresh_token');
        //     localStorage.removeItem('token');
        //     // window.location.href = '/login';  // 强制刷新页面并跳转
        //     setTimeout(() => {
        //         window.location.href = '/login';
        //     }, 60);
            
        // }
        return Promise.reject(err)
    }
)

export {https}